import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meiyunapp/common/url_base.dart';
import 'package:meiyunapp/entity/near_bystore_entity.dart';
import 'package:meiyunapp/page/gooddetail/good_detail_page.dart';
import 'package:meiyunapp/router/routers_pages.dart';

class GoodsWidget extends StatelessWidget {
  late NearBystoreListProducts data;

  GoodsWidget(this.data, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Get.toNamed(RouterPath.goods_detail,
            arguments: data.id, preventDuplicates: false);

        /*Navigator.push(context, MaterialPageRoute<void>(
          builder: (BuildContext context) {
            return GoodDetailPage(data.id);
          },
        ));*/
      },
      child: Container(
        margin: const EdgeInsets.symmetric(horizontal: 10),
        padding: const EdgeInsets.symmetric(vertical: 10),
        decoration: const BoxDecoration(
          border: Border(
            bottom: BorderSide(
              width: .5,
              color: Color(0xffeeeeee),
            ),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            CachedNetworkImage(
              imageUrl: UrlBase.getImage(data.coverImage),
              width: 119,
              height: 75,
              placeholder: (context, url) => const CupertinoActivityIndicator(),
              errorWidget: (context, url, error) => const Icon(Icons.error),
            ),
            const SizedBox(
              width: 10,
            ),
            Expanded(
              flex: 1,
              child: SizedBox(
                height: 75,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          data.name,
                          style: const TextStyle(fontSize: 16),
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                        ),
                        const SizedBox(
                          height: 2,
                        ),
                        data.price == null
                            ? const SizedBox()
                            : Text(
                                "券后${data.price!.toStringAsFixed(2)}",
                                style: const TextStyle(
                                    fontSize: 12, color: Colors.red),
                              ),
                      ],
                    ),
                    RichText(
                      text: TextSpan(
                        style: DefaultTextStyle.of(context).style,
                        children: [
                          const TextSpan(
                              text: "体验价:",
                              style:
                                  TextStyle(fontSize: 14, color: Colors.red)),
                          TextSpan(
                              text:
                                  "\t\t¥${data.activePrice.toStringAsFixed(2)}\t\t",
                              style: const TextStyle(
                                  fontSize: 18, color: Colors.red)),
                          TextSpan(
                              text: "¥${data.costPrice.toStringAsFixed(2)}",
                              style: const TextStyle(
                                fontSize: 12,
                                color: Color(0xff666666),
                                decoration: TextDecoration.lineThrough,
                              ))
                        ],
                      ),
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
